package com.chinameyer.workorders.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.chinameyer.workorders.bean.MeyerWorkOrders;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @Author meyer@HongYe
 */
@Repository
public interface WorkOrderMapper extends BaseMapper<MeyerWorkOrders> {

    @Select("SELECT * FROM meyer_work_orders " +
            "WHERE delete_time IS NULL AND " +
            "catalogue_id = #{catalogueId} AND "+
            "(#{productNo} = '' or product_no like CONCAT('%',#{productNo},'%')) " +
            "AND (#{productName} = '' or product_name like CONCAT('%',#{productName},'%')) " +
            "ORDER BY id DESC limit #{start},#{limit}")
    List<MeyerWorkOrders> selectAllWorkOrdersWithPaging(String productNo, String productName,int catalogueId, int start, Integer limit);


    @Select("SELECT count(*) FROM meyer_work_orders " +
            "WHERE delete_time IS NULL AND " +
            "catalogue_id = #{catalogueId} AND "+
            "(#{productNo} = '' or product_no like CONCAT('%',#{productNo},'%')) " +
            "AND (#{productName} = '' or product_name like CONCAT('%',#{productName},'%'))")
    int selectAllWorkOrdersWithoutPaging(String productNo, String productName,int catalogueId);

    @Select("SELECT * FROM meyer_work_orders " +
            "WHERE delete_time IS NULL AND " +
            "catalogue_id = #{catalogueId} AND "+
            "status = 0 AND "+
            "(#{productNo} = '' or product_no like CONCAT('%',#{productNo},'%')) " +
            "AND (#{productName} = '' or product_name like CONCAT('%',#{productName},'%')) " +
            "ORDER BY id DESC limit #{start},#{limit}")
    List<MeyerWorkOrders> selectAllActiveWorkOrdersWithPaging(String productNo, String productName, Integer catalogueId, Integer start, Integer limit);


    @Select("SELECT count(*) FROM meyer_work_orders " +
            "WHERE delete_time IS NULL AND " +
            "catalogue_id = #{catalogueId} AND "+
            "status = 0 AND "+
            "(#{productNo} = '' or product_no like CONCAT('%',#{productNo},'%')) " +
            "AND (#{productName} = '' or product_name like CONCAT('%',#{productName},'%'))")
    int selectAllActiveWorkOrdersWithoutPaging(String productNo, String productName, Integer catalogueId);
}
